<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include2923 :: header('协议库存信息查询--主表列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">协议名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="filename" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit
                        lay-filter="infoContractstore-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="infoContractstore-table" lay-filter="infoContractstore-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="infoContractstore-toolbar">
    <!--    <button shiro:hasPermission="gen:infoContractstore:add" class="pear-btn pear-btn-primary pear-btn-md"-->
    <!--            lay-event="add">-->
    <!--        <i class="layui-icon layui-icon-add-1"></i>-->
    <!--        新增-->
    <!--    </button>-->
    <!--    <button shiro:hasPermission="gen:infoContractstore:remove" class="pear-btn pear-btn-danger pear-btn-md"-->
    <!--            lay-event="batchRemove">-->
    <!--        <i class="layui-icon layui-icon-delete"></i>-->
    <!--        删除-->
    <!--    </button>-->
    <button class="pear-btn pear-btn-primary pear-btn-md"
            id="uploadFile" lay-event="uploadFile">
        <i class="layui-icon layui-icon-add-1"></i>
        导入
    </button>
</script>

<script type="text/html" id="infoContractstore-bar">
    <button shiro:hasPermission="info:infoContractstore:edit" class="pear-btn pear-btn-primary pear-btn-sm"
            lay-event="edit" title="修改"><i class="layui-icon layui-icon-edit"></i>
    </button>
    <button shiro:hasPermission="info:infoContractstore:remove" class="pear-btn pear-btn-danger pear-btn-sm"
            lay-event="remove" title="删除"><i class="layui-icon layui-icon-delete"></i>
    </button>
    <button class="pear-btn pear-btn-md pear-btn-warming"
            lay-event="viewdtl" type="button">
        <i class="layui-icon layui-icon-export"></i>
        详情查看
    </button>
    <button class="pear-btn pear-btn-md pear-btn-warming"
            lay-event="downloadbyrecordid" type="button">
        <i class="layui-icon layui-icon-export"></i>
        文件下载
    </button>
</script>


<script type="text/html" id="infoContractstore-type">
    {{#if (d.dataState == '0') { }}
    <span class="layui-badge layui-bg-orange">开启</span>
    {{# }else if(d.dataState == '-1'){ }}
    <span class="layui-badge layui-bg-blue">关闭</span>
    {{# } }}
</script>

<th:block th:include="include2923 :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery','upload'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var upload = layui.upload;

        var MODULE_PATH = rootPath + "/InfoContractstoreController/";
        var MODULE_PATH_FILE = rootPath + "/InfoFileController/";
        var cols = [
            [
                // {type: 'checkbox'},
                //
                // {title: '主键ID', field: 'id', align: 'center'},

                {title: '协议库存名称', field: 'filename', align: 'center',width: 600},

                {title: '导入时间', field: 'creattime', align: 'center'},

                {title: '版本信息', field: 'vertion', align: 'center'},

                // {title: '备注', field: 'memo', align: 'center'},

                {title: '操作', toolbar: '#infoContractstore-bar', align: 'center'}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#infoContractstore-table',
            url: MODULE_PATH + 'list',
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#infoContractstore-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }],
            before: function(options){
                options.where.isdelete != 1; // 修改或额外追加 where 属性
            },
            done: function (res) {
                uploadT();
            }
        });

        //table图标事件绑定
        table.on('tool(infoContractstore-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            } else if (obj.event === 'viewdtl') {
                window.viewdtl(obj);
            } else if (obj.event === 'downloadbyrecordid') {
                window.downloadbyrecordid(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(infoContractstore-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            } else if (obj.event === 'uploadFile') {
                window.uploadFile(obj);
            }
        });

        //查询按钮绑定
        form.on('submit(infoContractstore-query)', function (data) {
            table.reload('infoContractstore-table', {where: data.field})
            return false;
        });


        //添加
        window.add = function () {
            layer.open({
                type: 2,
                title: '新增',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'add'
            });
        }
        //修改
        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['700px', '300px'],
                content: MODULE_PATH + 'edit/' + obj.data['id']
            });
        }
        //删除
        window.remove = function (obj) {
            layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //批量删除
        window.batchRemove = function (obj) {
            var data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            var ids = "";
            for (var i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('infoContractstore-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }
        //刷新按钮
        window.refresh = function () {
            table.reload('infoContractstore-table');
        }
        //添加
        function uploadT() {
            upload.render({
                elem: '#uploadFile',
                url: MODULE_PATH + 'uploadFile',
                exts: 'xlsx',
                choose: function (obj) {
                    // $('#uploadFileAction').click()
                    showLoad();
                },
                done: function (res) {
                    closeLoad(showLoad());//回调成功后关闭动画
                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 1, time: 5000});
                        table.reload('infoContractstore-table')

                    } else {
                        layer.msg(res.msg, {icon: 2, time: 5000});
                    }
                },
                error: function (err) {
                    layer.alert('导入出现异常', {icon: 2});
                }
            });
        }

        function showLoad() {
            return layer.msg('数据导入中，请耐心等待...', { icon: 6, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: 'auto', time: 1000000 });
        }

        function closeLoad(index) {
            layer.close(index);
        }

        window.viewdtl = function (obj) {
            layer.open({
                type: 2,
                title:  obj.data['filename']+'--协议库存详情',
                area: ['90%', '80%'],
                shade: 0.5,
                content: MODULE_PATH + 'viewdtl/' + obj.data['id']
            });
        }

        window.downloadbyrecordid = function (obj) {
            var url = MODULE_PATH_FILE + "downloadbyrecordid/" + obj.data['id'];
            downloadFile(url, obj.data['filename']);
        }

    })
</script>
</html>